﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Baza.EF.BLL;
using Baza.EF.DAL;


namespace Pep_3014_3070_Desktop
{
    public partial class AddApartment : Form
    {
        public AddApartment()
        {
            InitializeComponent();
        }
        private void btnSpremi_Click(object sender, EventArgs e)
        {
            Apartments apartment = new Apartments();
            ApartmentType apartmentType = new ApartmentType();
            apartmentType = (ApartmentType)cmbTipApartmana.SelectedItem;


            bool checkedValue = false;

            if (checkBoxLift.Checked)
                checkedValue = true;

            Address address = new Address();

            Cities city = new Cities();
            city = (Cities)cmbGrad.SelectedItem;

            DateTime date;
            date = DateTime.MinValue;


            address.CityID = city.CityID;
            address.StreetNumber = Int32.Parse(BrojUliceInput.Text);
            address.Address1 = Adresa1Input.Text;
            address.Address2 = Adresa2Input.Text;
            address.ApartmentNumber = Int32.Parse(BrojApartmanaInput.Text);


            apartment.Title = NazivApartmanaInput.Text;
            apartment.ApartmentTypeID = apartmentType.ApartmentTypeID;
            apartment.Bathrooms = Int32.Parse(BrojKupatilaInput.Text);
            apartment.Toilets = Int32.Parse(BrojToaletaInput.Text);
            apartment.MaxGuests = Int32.Parse(maxBrGostijuInput.Text);
            apartment.MaxAdults = Int32.Parse(maxBrOdraslihInput.Text);
            apartment.MaxChildren = Int32.Parse(MaxBrDjeceInput.Text);
            apartment.MaxBabies = Int32.Parse(MaxBrBebaInput.Text);
            apartment.AdresID = DAIznajmljivaciApartmani.ApartmentAddressInsert(address);
            apartment.CheckIn = date;
            apartment.CheckOut = date;
            apartment.Floor = Int32.Parse(SpratInput.Text);
            apartment.Elevator = checkedValue;
            apartment.AvgCleaningTime = date;
            apartment.MinStay = Int32.Parse(MinDaniOstankaInput.Text);
            apartment.MaxStay = Int32.Parse(MaxDaniOstankainput.Text);
            apartment.Beds = Int32.Parse(BrojSobaInput.Text);
            apartment.Bathrooms = Int32.Parse(BrojToaletaInput.Text);




            Owners o = (Owners)cmbIznajmljivac.SelectedItem;

            DAIznajmljivaciApartmani.InsertApartment(apartment, o);

            MessageBox.Show(Global.GetString("appart_succ"), "Apartmani", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }



        private void AddApartment_Load(object sender, EventArgs e)
        {
            cmbIznajmljivac.DataSource = DAIznajmljivaciApartmani.SelectOwners();
            cmbIznajmljivac.DisplayMember = "FirstName,LastName";

            cmbTipApartmana.DataSource = DAIznajmljivaciApartmani.ApartmentTypeSelect();
            cmbTipApartmana.DisplayMember = "Name";

            cmbGrad.DataSource = DAIznajmljivaciApartmani.SelectCities();
            cmbGrad.DisplayMember = "Name";
        }


        private void cmbIznajmljivac_Format(object sender, ListControlConvertEventArgs e)
        {
            string lastname = ((Owners)e.ListItem).FirstName;
            string firstname = ((Owners)e.ListItem).LastName;
            e.Value = lastname + " " + firstname;
        }

        private void btnOdustani_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
